package com.ihelp.rest.mis.platform.dao;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.ihelp.rest.base.hibernate4.BaseHibernateDao;
import com.ihelp.rest.mis.pojo.SysUser;

@Repository
public class UserDao extends BaseHibernateDao<SysUser, String>{

	@Autowired
	private JdbcTemplate jdbcTemplate;
	
	/**
	 * 根据用户名称查询用户
	 * @param loginName
	 * @return
	 */
	public SysUser querySysUser(String loginName){
		return this.unique("from SysUser a where a.loginName=?", loginName);
	}
	
	/**
	 * 查询系统用户
	 * @param loginName
	 * @return
	 */
	public SysUser querySystemUser(String loginName){
		return this.unique("from SysUser a where a.loginName=? and a.type=0", loginName);
	}
	
	public List<SysUser> querySysUser(){
		return this.list("select new com.ihelp.rest.mis.pojo.SysUser(a.uuid, a.name) from SysUser a ");
	}
	
	
	public int querySysUserCnt(String uuid){
		String sql = "select count(*) from users t where t.saleuserid = '"+uuid+"' or t.manageruserid ='"+uuid+"' or t.assistantuserid = '"+uuid+"' ";
		return this.jdbcTemplate.queryForInt(sql);
	}
}
